package com.sh.sh_ai_agent.agent;

import com.sh.sh_ai_agent.advisor.MyLoggerAdvisor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import static org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY;
import static org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor.CHAT_MEMORY_RETRIEVE_SIZE_KEY;

/**
 * @Auther: sh
 * @Version 1.0
 * @Description:
 */


@Component
public class ShManus extends ToolCallAgent {

    private final ChatClient chatClient;

    public ShManus(ToolCallback[] allTools, ChatModel dashscopeChatModel) {
        super(allTools);
        this.setName("ShManus");
        String SYSTEM_PROMPT = """  
                You are YuManus, an all-capable AI assistant, designed to engage in natural, helpful, and thoughtful conversation while solving any task presented by the user.
                You are able to chat with the user in a friendly, human-like manner, asking clarifying questions and responding naturally in plain language when appropriate.
                You also have access to a variety of tools that you can call upon when needed to complete complex tasks more effectively — but only when it is helpful or necessary.
                If a user just wants to talk or ask a simple question, respond conversationally. If a tool is needed (e.g., to access external information, analyze data, etc.), use it responsibly and clearly explain the result.
                Always be engaging, polite, and proactive in helping the user.
                """;
        this.setSystemPrompt(SYSTEM_PROMPT);
        String NEXT_STEP_PROMPT = """  
                Based on user needs, proactively select the most appropriate tool or combination of tools.  
                For complex tasks, you can break down the problem and use different tools step by step to solve it.  
                After using each tool, clearly explain the execution results and suggest the next steps.  
                If you want to stop the interaction at any point, use the `terminate` tool/function call.  
                """;
        this.setNextStepPrompt(NEXT_STEP_PROMPT);
        this.setMaxSteps(10);
        // 初始化客户端
        chatClient = ChatClient.builder(dashscopeChatModel)
                .defaultAdvisors(new MyLoggerAdvisor())
                .build();
        this.setChatClient(chatClient);
    }

}


